<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Base extends Controller
{
    // Название сайта
    protected $title = 'Best Of Books';
    
	// Модели
	protected $main_model = null;
	protected $user_model = null;
    protected $category_model = null;
    protected $page_model = null;
    //protected $setting_model = null; 
    protected $book_model  = null;
	
	// Темплейты
	protected $main_tpl = 'main_tpl';
    
    // Юзер
    protected $user = null;
    
    // Настройки
    //protected $settings = null;
    protected $slider        = false;
    protected $selected_page = 0;   // Главная

	public function before()
	{
		parent::before();
        
        // Юзер
        $this->user = Auth::instance()->get_user();
		
		// Модели
		$this->main_model = new Model_Main;
		$this->user_model = new Model_Users;
        $this->category_model = new Model_Categories;
        $this->page_model     = new Model_Pages;
        //$this->setting_model  = new Model_Settings;
        $this->book_model  = new Model_Books;
        
        // Настройки
        //$this->settings = $this->setting_model->process_settings($this->setting_model->get_settings());
        
		// Темплейты
		$this->main_tpl = new View($this->main_tpl);
	}
	
	public function print_template($title, $content, $menu = null, $message = null)
	{
        if(!$menu)
            $menu = array();
        
		$this->main_tpl->title   = $title.' - '.$this->title;
		$this->main_tpl->content = $content;
        $this->main_tpl->slider  = $this->slider;
        $this->main_tpl->selected_page = $this->selected_page; 
        
        $this->main_tpl->pages    = $this->page_model->get_pages();
        $this->main_tpl->menu     = $menu;
        $this->main_tpl->user     = $this->user;
        $this->main_tpl->message  = $message;
        
        $bestsellers = $this->book_model->get_global_popular_books();
        $this->main_model->transliterate_array($bestsellers, 'name');
        $this->main_tpl->bestsellers = $bestsellers; 
        
        $pages = $this->page_model->get_pages();
        $this->main_tpl->pages = $pages;
		
		$this->response->body($this->main_tpl);
	}

} // End Base
